/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author yunfengqiao
 */
public class FindFileByContent {

	private static ArrayList<String> filelist = new ArrayList<String>();

	// private static ArrayList<String> filelistname = new ArrayList<String>();

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String[] args) {
		String filePath = "Y:\\PromotionCodeAddRemoveControllerCmdImpl.java";
		//getFile(filePath);
		//System.out.println(filelist.size());
		changjava(filePath);
		//System.out.println(list1.size());
		// for (String string : list1) {
		// System.out.println(string);
		// }
	}

	/*
	 * 通过递归得到某一路径下所有的目录及其文件
	 */

	static void getFile(String filePath) {
		// System.out.println(filePath);
		File root = new File(filePath);
		// System.out.println(root.isDirectory());
		File[] files = root.listFiles();

		for (File file : files) {
			if (file.isDirectory()) {
				/*
				 * 递归调用
				 */
				getFile(file.getAbsolutePath());

			} else {
				String filename = file.getName();
				if (filename.contains(".java")
						&& !file.getAbsolutePath().contains(".svn")
						&& file.getAbsolutePath().contains("ui")
						&& !file.getAbsolutePath().contains("target")) {
					filelist.add(file.getAbsolutePath());
				}
			}
		}
	}

	static ArrayList<String> getFiles() {
		ArrayList<String> list1 = new ArrayList<String>();
		// getFile(filePath);
		InputStream in = null;
		OutputStream outputStream = null;
		for (int i = 0; i < filelist.size(); i++) {
			try {

				byte[] tempbytes = new byte[(int) new File(filelist.get(i))
						.length()];
				int byteread = 0;
				in = new FileInputStream(filelist.get(i));
				while ((byteread = in.read(tempbytes)) != -1) {
				}
				String s = new String(tempbytes);
				if (s.contains("GWTLogger.INSTANCE.debug")) {
					outputStream = new FileOutputStream(new File(
							filelist.get(i)));
					list1.add(filelist.get(i));
					outputStream.write(s.replace("/*[\\d\\s]+*/", "").getBytes(
							"UTF-8"));
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			} finally {
				if (in != null) {
					try {
						in.close();

					} catch (IOException e1) {
					}
				}
				if (outputStream != null) {
					try {
						outputStream.close();

					} catch (IOException e1) {
					}
				}
			}
		}
		return list1;
	}

	static void changjava(String path) {
		InputStream in = null;
		OutputStream outputStream = null;
		try {
			byte[] tempbytes = new byte[(int) new File(path).length()];
			int byteread = 0;
			in = new FileInputStream(new File(path));
			while ((byteread = in.read(tempbytes)) != -1) {
			}			
			String s = new String(tempbytes);
			System.out.println("/\\*[\\d\\s]+\\*/");
			outputStream = new FileOutputStream(new File(path));
			outputStream.write(s.replaceAll("/\\*[\\d\\s]+\\*/", "").getBytes(
						"UTF-8"));
			
		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();

				} catch (IOException e1) {
				}
			}
			if (outputStream != null) {
				try {
					outputStream.close();

				} catch (IOException e1) {
				}
			}
		}
	}
}
